///////////////////////////////////////////////////////////
//  SaveCheckListCommand.cpp
//  Implementation of the Class SaveCheckListCommand
//  Created on:      21-Sep-2013 12:07:30 PM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#include "SaveCheckListCommand.h"
#include "CurrentCommand.h"
#include "DataManager.h"

using namespace UI;
using namespace UI::CMD;

SaveCheckListCommand::SaveCheckListCommand(CCreateCheckListView* createCheckList, CCheckListView* checkList, CSaveView* saveView)
{
  this->m_type = ICommand::SAVECHECKLIST_CMD;
  this->m_checkListView = checkList;
  this->m_createCheckListView = createCheckList;
  this->m_saveView = saveView;
}


SaveCheckListCommand::~SaveCheckListCommand()
{

}


void SaveCheckListCommand::Execute()
{
  switch(CurrentCommand::GetInstance()->GetNewOrEditCommand())
  {
  case ICommand::NEWCHECKLIST_CMD:
    {
      IPage* newPage = this->m_createCheckListView->GetPage();
      newPage->SetName(this->m_saveView->GetNameLabel());
			newPage->UpdateBuildTime();
      this->m_checkListView->AppendPage(newPage);
      this->m_checkListView->Refresh();
    }
    break;
  case ICommand::EDITCHECKLIST_CMD:
    {
      this->m_checkListView->EditPage(this->m_createCheckListView->GetPage()); 
    }
    break;
  default: break;
  }
  // Set current command
  DataManager::GetInstance()->Save();
  CurrentCommand::GetInstance()->SetCurrentCommand(this->m_type);
  CurrentCommand::GetInstance()->SetNewOrEditCommand(ICommand::UNKNOWN_CMD);
}


ICommand::CommandType SaveCheckListCommand::GetType()
{
	return this->m_type;
}